<?php
// 节点模型
class NodeModel extends BaseModel
{
    protected $_validate = array(
        array('name', 'require', '节点名称必须存在！'),
        array('name', 'checkNode', '节点已经存在', 0, 'callback'),
    );

    public function checkNode()
    {
        $map['name'] = getPost('name');
        $pid = getGetOrPost('pid');
        $map['pid'] = isset($pid) ? $pid : 0;
        $map['status'] = 1;
        if (!empty($_POST['id'])) {
            $map['id'] = array('neq', $_POST['id']);
        }
        $result = $this->where($map)->field('id')->find();
        if ($result) {
            return false;
        } else {
            return true;
        }
    }

    /**
     * 获取节点信息
     * @author Ice <iceinto@mallog.com.cn>
     */
    public function getNodes($pid, $level)
    {
        $map = array();
        $map['pid'] = $pid;
        $map['level'] = $level;
        return $this->where($map)->select();
    }
}

?>